<script setup lang='ts'>
import { ref, computed } from "vue";
import { useRoute } from "vue-router";
import { findHotGoods } from "../../api/product";

const route = useRoute();
const props = defineProps({
  type: {
    type: Number,
    default: 1,
  },
});

let goodsList = ref(null);

findHotGoods({ id: route.params.id, type: props.type }).then((res) => {
  goodsList.value = res;
});

const titleObj = { 1: "24小时热销榜", 2: "周热销榜", 3: "总热销榜" };

const title = computed(() => {
  return titleObj[props.type];
});
</script>

<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <template v-if="goodsList !== null">
      <goods-item
        v-for="item in goodsList"
        :key="item.id"
        :goods="item"
      ></goods-item>
    </template>
  </div>
</template>

<style scoped lang='less'>
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 16px;
    line-height: 70px;
    padding-left: 20px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;
    img {
      width: 200px;
      height: 200px;
    }
    p {
      margin: 0 10px;
    }
    &:hover {
      transform: none;
      box-shadow: none;
    }
  }
}
</style>